package com.yxy.ms.manager.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.yxy.ms.manager.dao.A22UrlMappingMapper;
import com.yxy.ms.manager.dao.A23DataFileMapper;
import com.yxy.ms.manager.dao.A36OrganTransformMapper;
import com.yxy.ms.manager.dao.A36TollIntervalInfoMapper;
import com.yxy.ms.manager.dao.ClearDataTempMapper;
import com.yxy.ms.manager.dao.ClearErrorInfoMapper;
import com.yxy.ms.manager.dao.ClearMessageInfoMapper;
import com.yxy.ms.manager.dao.ClearMessageValidateRecordMapper;
import com.yxy.ms.manager.dao.ClearPendingChargeMapper;
import com.yxy.ms.manager.dao.ClearSendRecordMapper;
import com.yxy.ms.manager.dao.ErrorDataMapper;
import com.yxy.ms.manager.dao.M21DataSendRecordMapper;
import com.yxy.ms.manager.dao.TransExitMapper;
import com.yxy.ms.manager.dao.TransGantryEtcMapper;
import com.yxy.ms.manager.entity.po.A22UrlMapping;
import com.yxy.ms.manager.entity.po.A23DataFile;
import com.yxy.ms.manager.entity.po.A36OrganTransform;
import com.yxy.ms.manager.entity.po.A36TollIntervalInfo;
import com.yxy.ms.manager.entity.po.ClearDataTemp;
import com.yxy.ms.manager.entity.po.ClearErrorInfo;
import com.yxy.ms.manager.entity.po.ClearErrorInfoKey;
import com.yxy.ms.manager.entity.po.ClearMessageInfo;
import com.yxy.ms.manager.entity.po.ClearMessageInfoKey;
import com.yxy.ms.manager.entity.po.ClearMessageValidateRecord;
import com.yxy.ms.manager.entity.po.ClearPendingCharge;
import com.yxy.ms.manager.entity.po.ClearSendRecord;
import com.yxy.ms.manager.entity.po.ErrorData;
import com.yxy.ms.manager.entity.po.M21DataSendRecord;
import com.yxy.ms.manager.entity.po.TransExit;
import com.yxy.ms.manager.entity.po.TransGantryEtc;
import com.yxy.ms.manager.service.MonitorService;

@Service
public class MonitorServiceImpl implements MonitorService {

    @Autowired
    ErrorDataMapper errorDataMapper;
    @Autowired
    A36OrganTransformMapper a36OrganTransformMapper;
    @Autowired
    A36TollIntervalInfoMapper a36TollIntervalInfoMapper;
    @Autowired
    A22UrlMappingMapper a22UrlMappingMapper;
    @Autowired
    A23DataFileMapper a23DataFileMapper;
    @Autowired
    ClearDataTempMapper clearDataTempMapper;
    @Autowired
    ClearPendingChargeMapper clearPendingChargeMapper;
    @Autowired
    ClearErrorInfoMapper clearErrorInfoMapper;
    @Autowired
    ClearMessageInfoMapper clearMessageInfoMapper;
    @Autowired
    TransGantryEtcMapper transGantryEtcMapper;
    @Autowired
    ClearSendRecordMapper clearSendRecordMapper;
    @Autowired
    TransExitMapper transExitMapper;
    @Autowired
    M21DataSendRecordMapper m21DataSendRecordMapper;
    @Autowired
    ClearMessageValidateRecordMapper clearMessageValidateRecordMapper;

    @Override
    public Page<ErrorData> findErrorDataList(Map<String, Object> params) {
        return errorDataMapper.findErrorDataList(params);
    }

    @Override
    public ErrorData getById(String id) {
        return errorDataMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<A36OrganTransform> findA36OrganTransformList(Map<String, Object> params) {
        return a36OrganTransformMapper.findAll(params);
    }

    @Override
    public Page<A36TollIntervalInfo> findA36TollIntervalInfo(Map<String, Object> params) {
        return a36TollIntervalInfoMapper.findAll(params);
    }

    @Override
    public Page<A22UrlMapping> findA22UrlMapping(Map<String, Object> params) {
        return a22UrlMappingMapper.findAll(params);
    }

    @Override
    public A22UrlMapping getA22UrlMappingEdit(String id) {
        return a22UrlMappingMapper.getById(id);
    }

    @Override
    public List<A22UrlMapping> findA22UrlMappingDataType() {
        return a22UrlMappingMapper.findA22UrlMappingDataType();
    }

    @Override
    public Page<ClearDataTemp> findClearDataTempList(Map<String, Object> params) {
        return clearDataTempMapper.findAll(params);
    }

    @Override
    public Page<ClearMessageInfo> findClearMessageInfoList(Map<String, Object> params) {
        return clearMessageInfoMapper.findAll(params);
    }

    @Override
    public Page<ClearErrorInfo> getClearErrorInfoList(Map<String, Object> params) {
        return clearErrorInfoMapper.findAll(params);
    }

    @Override
    public List<?> loadTransTypeCodeDropList() {
        return clearDataTempMapper.findAllTransTypeCode();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteClearTempData(Long mid, Integer transTypeCode) {
        clearDataTempMapper.deleteByPrimaryKey(new ClearDataTemp(mid, transTypeCode));
    }

    @Override
    public TransGantryEtc getTransGantryEtcById(Long mid) {
        return transGantryEtcMapper.selectByPrimaryKey(mid);
    }

    @Override
    public TransExit getTransExitById(Long mid) {
        return transExitMapper.selectByPrimaryKey(mid);
    }

    @Override
    public void saveA22UrlMapping(A22UrlMapping record) {
        if (StringUtils.isBlank(record.getId())) {
            a22UrlMappingMapper.insertSelective(record);
        } else {
            //
        }

    }

    @Override
    public ClearMessageInfo getClearMessageInfo(ClearMessageInfoKey key) {
        return clearMessageInfoMapper.selectByPrimaryKey(key);
    }

    @Override
    public Page<A23DataFile> findA23DataFile(Map<String, Object> params) {
        return a23DataFileMapper.findA23DataFile(params);
    }

    @Override
    public Page<M21DataSendRecord> findgetM21DataSendRecord(Map<String, Object> params) {
        return m21DataSendRecordMapper.findAll(params);
    }

    @Override
    public ClearErrorInfo getClearErrorInfo(String fileVersion, Integer transTypeCode, Date createTime) {
        return clearErrorInfoMapper.selectByPrimaryKey(new ClearErrorInfoKey(fileVersion, transTypeCode, createTime));
    }

    @Override
    public Page<ClearSendRecord> findClearSendRecords(Map<String, Object> params) {
        return clearSendRecordMapper.findAll(params);
    }

    @Override
    public Page<ClearPendingCharge> getClearPendingCharges(Map<String, Object> params) {
        return clearPendingChargeMapper.findAll(params);
    }

    @Override
    public Page<ClearMessageValidateRecord> getClearMessageValidateRecords(Map<String, Object> params) {
        return clearMessageValidateRecordMapper.findAll(params);
    }

}
